package com.vne.skyemart.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.SessionAttributes;
import org.springframework.web.servlet.ModelAndView;

import com.vne.skyemart.model.PaymentType;
import com.vne.skyemart.service.PaymentTypeService;

@Controller
@SessionAttributes
@RequestMapping("/paymentType")
public class PaymentTypeController {

	@Autowired
	private PaymentTypeService paymentTypeService;

	@RequestMapping(value = "/save", method = RequestMethod.POST)
	public ModelAndView savePaymentType(@ModelAttribute(" paymentType") PaymentType paymentType,
			BindingResult result) {
		paymentTypeService.addPaymentType(paymentType);
		return new ModelAndView("redirect:/paymentType.html");
	}

	@RequestMapping(method = RequestMethod.GET)
	public String listPaymentType(Model model) {
		model.addAttribute("paymentType",  paymentTypeService.listPaymentType());

		return "PaymentTypeList";
	}

	@RequestMapping(value = "/add", method = RequestMethod.GET)
	public ModelAndView addPaymentType(@ModelAttribute("paymentType") PaymentType paymentType,
			BindingResult result) {
		return new ModelAndView("addPaymentType");
	}

}